package com.lemon.smartsafety.ui.adapter.hidden.main;

import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.lemon.smartsafety.R;
import com.lemon.smartsafety.entity.hidden.HiddenMainUIVo;
import com.lemon.smartsafety.entity.hidden.MainHiddenUIItemBase;
import com.lemon.smartsafety.listener.RecyclerTClickListener;
import com.lemon.smartsafety.utils.common.StringUtils;

import kale.adapter.item.AdapterItem;

/**
 * Created by Cooliean on 16/1/27.
 */
public class HiddenMainItem implements AdapterItem<MainHiddenUIItemBase<HiddenMainUIVo>> {

    private ImageView iconView, imageArrow;
    private TextView mTextTitle, mTextTip;
    private RelativeLayout mMainLayout;
    private LinearLayout mRippleLayout;

    private RecyclerTClickListener<MainHiddenUIItemBase<HiddenMainUIVo>> mRecycleItemClickListener;
    private MainHiddenUIItemBase<HiddenMainUIVo>                         mData;
    private int                                                          mPosition;


    public HiddenMainItem(RecyclerTClickListener<MainHiddenUIItemBase<HiddenMainUIVo>> recycleItemClickListener) {
        mRecycleItemClickListener = recycleItemClickListener;
    }

    @Override
    public int getLayoutResId() {
        return R.layout.item_icon_title_tip_arrow;
    }

    @Override
    public void bindViews(View root) {
        mRippleLayout = (LinearLayout) root.findViewById(R.id.ripple);
        mMainLayout = (RelativeLayout) root.findViewById(R.id.itemMainLayout);
        iconView = (ImageView) root.findViewById(R.id.imageIcon);
        imageArrow = (ImageView) root.findViewById(R.id.imageArrow);
        mTextTitle = (TextView) root.findViewById(R.id.itemText);
        mTextTip = (TextView) root.findViewById(R.id.itemSubText);
    }

    @Override
    public void setViews() {
//        mMainLayout.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                if (mRecycleItemClickListener != null) {
//                    mRecycleItemClickListener.onItemClick(mData, mPosition);
//                }
//            }
//        });
        mRippleLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mRecycleItemClickListener != null) {
                    mRecycleItemClickListener.onItemClick(mData, mPosition);
                }
            }
        });
   /*     mRippleLayout.setOnRippleCompleteListener(new RippleView.OnRippleCompleteListener() {
            @Override
            public void onComplete(RippleView rippleView) {
                if (mRecycleItemClickListener != null) {
                    mRecycleItemClickListener.onItemClick(mData, mPosition);
                }
            }
        });*/
    }

    @Override
    public void handleData(MainHiddenUIItemBase<HiddenMainUIVo> data, int position) {
        mTextTitle.setText(data.getData().getTitle());
        if (StringUtils.nullValue(data.getData().getTip()).length() != 0) {
            mTextTip.setText(data.getData().getTip());
            mTextTip.setVisibility(View.VISIBLE);
        }
        mPosition = position;
        mData = data;
        if (position == 4 || position == 5 || position == 6) {
            imageArrow.setVisibility(View.VISIBLE);
            mRippleLayout.setEnabled(true);
        } else {
            imageArrow.setVisibility(View.INVISIBLE);
            mRippleLayout.setEnabled(false);
        }
    }

}
